package back.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.lang.Nullable;

import back.service.FuckServiceImp;

@Configuration
@PropertySource("classpath:application.properties")//这个是把属性添加到环境中,即Environment对象中
@ImportResource("classpath:spring-core.xml")
@MapperScan("back.mappers")
public class AppConfig {
	@Bean
	//BeanPostProcessor在创建对象后进行处理@Value,
	FuckServiceImp myservice(/* @Value("${jdbc_url}")  */@Nullable String url) {
		return new FuckServiceImp();
	}
    @Bean
    //它的postProcessBeanFactory方法配置每个bean定义中的占位符，即默认的"${}"替换为实际的值
    //如果不配置propertySources，它就会从Environment中获取属性
    //这个bean方法必须是static，因为这是容器早期初始化。否则造成当前类过早被初始化，甚至引起连锁后果
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
    	var psp=new PropertySourcesPlaceholderConfigurer();
//    	psp.setPropertySources(propertySources);
          return psp;
    }
}
